package com.wrenchserver.service.impl.sys;

import java.util.Date;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wrenchserver.dao.sys.TUserDao;
import com.wrenchserver.entity.sys.UserEntity;
import com.wrenchserver.pojo.sys.TUser;
import com.wrenchserver.service.sys.TUserService;
import com.wrenchserver.util.DateUtil;
import com.wrenchserver.util.JsonUtil;
import com.wrenchserver.util.UUIDGenerator;


@Service("userService")  
public class TUserServiceImpl implements TUserService {
	@Autowired
    private TUserDao userDao;  
    
    public TUser getUserById(int userId) {  
        // TODO Auto-generated method stub  
        return this.userDao.selectByPrimaryKey(userId);  
    }

    /**
	 * 创建用户
	 * @param jsonStr
	 * @return
	 * @throws Exception
	 */
	public String createUser(String jsonStr) throws Exception {
		UserEntity userEntity = (UserEntity) JsonUtil.getObject4JsonString(
				jsonStr, UserEntity.class);
		userEntity.setId(UUIDGenerator.generate());
		userEntity.setCreateUser(userEntity.getUserCde());
		Date createTime = new Date();
		userEntity.setCreateTime(DateUtil.datetimeFormat.format(createTime));
		userEntity.setState("1");
		int i= userDao.createUser(userEntity);
		
		return null;
	}
	public UserEntity getByUsername(String username){  
        return userDao.getByUsername(username);  
}  
	public Set<String> getRoles(String username){  
	        return userDao.getRoles(username);  
	}  
	public Set<String> getPermissions(String username){  
	       return userDao.getPermissions(username);  
	}  
}
